# 爬取成功

import requests
import re
ua = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36"
url = 'https://zz.58.com/ershouche/?PGTID=0d100000-0015-68d4-6d80-507b0eba880a&ClickID=5'
response = requests.get(url,headers={'User-Agent':ua})
# print(response.text)

# 爬取标题
# name = re.findall(
#     r'<span class="info_link">\s*(.*?)\s*</span>',
#     response.text, re.S          # re.S 让 . 匹配换行
# )
# print(name)

# 爬取封面
img_list= re.findall(r'<img\s+class="info_pic"\s+data-original="(.*?)"\s+src="(.*?)"',response.text)
print(img_list)
for img in img_list:
    print(img[0],type(img))

    response = requests.get(img[0],headers={'User-Agent':ua})
    name =img[0].split('/')[-1].split('?')[0]

    with open(f'../tu/{name}','wb') as f:
        f.write(response.content)
